<?php
class Advertisement_overflowModel extends Model {
	public function get_primary_key() {
		return $this->primary_key = 'id'; //设置主键
	}
	public function get_fields() {
		return $this->get_table_fields();
	}

	/**
	 * 按用户分组，查询用户数据
	 * @return array
	 */
	public function getCount()
	{
		$result = $this->db->query('SELECT count(DISTINCT(uid)) num FROM `ca_advertisement_overflow`')->row_array();
		if(empty($result)){
			return [];
		}
		return $result['num'];
	}

	/**
	 * 按用户分组，查询用户数据
	 * @return array
	 */
	public function getGroupData($page,$pagesize)
	{
		$sql = 'SELECT * FROM `ca_advertisement_overflow` group by uid desc limit '.$page.','.$pagesize;
		$result = $this->db->query($sql)->result_array();
		if(empty($result)){
			return [];
		}
		return $result;
	}

	/**
	 * 按用户uid，查询用户数据
	 * @return array
	 */
	public function getIncomeInfoCount($uid)
	{
		$result = $this->db->query('SELECT count(id) num FROM `ca_advertisement_overflow` where uid='.$uid)->row_array();
		if(empty($result)){
			return [];
		}
		return $result['num'];
	}

	/**
	 * 按用户uid，查询用户数据
	 * @return array
	 */
	public function getIncomeInfoData($page,$pagesize,$uid)
	{
		$sql = 'SELECT * FROM `ca_advertisement_overflow` where uid='.$uid.' limit '.$page.','.$pagesize;
		$result = $this->db->query($sql)->result_array();
		if(empty($result)){
			return [];
		}
		return $result;
	}


	/**
	 * 根据查询用户数据
	 * @return array
	 */
	public function getDataByUid($uid,$page,$pagesize)
	{
		$result = $this->db->query('SELECT * FROM `ca_advertisement_overflow` where uid = $uid order by id desc limit $page,$pagesize')->result_array();
		if(empty($result)){
			return [];
		}
		return $result;
	}

	
}